package demo.metrics;

import io.micrometer.core.instrument.FunctionCounter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.binder.MeterBinder;
import util.MetricsUtil;

public class AppMetrics implements MeterBinder{
	
	@Override
    public void bindTo(MeterRegistry meterRegistry) {
		System.out.println("\n***************\n\n\nmeterRegistry="+meterRegistry+","+meterRegistry.getClass());
		// io.micrometer.prometheus.PrometheusMeterRegistry@36a6307
        Gauge.builder("statusInvokeCount", MetricsUtil.statusInvokeCount, c -> c.get())
                // .tags("host", "localhost")
                // .description("demo of custom meter binder")
                .register(meterRegistry);
        // lambada 无法打断点 换成 AtomicLongToDouble
        FunctionCounter.builder("statusInvokeCount2", MetricsUtil.statusInvokeCount, new AtomicLongToDouble()).register(meterRegistry);
        // # TYPE statusInvokeCount2_total counter
        // statusInvokeCount2_total 3.0
        // # TYPE statusInvokeCount gauge
        // statusInvokeCount 3.0
        
        MetricsUtil.getCountMap();
       
        
    }
	
}